/**
 * 
 */
package com.jie.eclipse.pan.swtitem.table.sort;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;

import com.jie.eclipse.pan.data.BaseDataEntity;

/**
 * @author yanjie
 *
 */
public class LogSorter extends ViewerSorter{

	 private int sortType ;
	 private static final int SN = 1;
    private static final int OWNER = 2;
    private static final int PAGENAME = 3;
    private static final int ERRMSG = 4;
    private static final int STATUS = 5;
    private static final int PAGEPATH = 6;
    private static final int CRTDAY = 7;
    private static final int UPDDAY = 8;
    private static final int HOSTIP = 9;
    private static final int CRTNAME = 10;
    
    public  static final LogSorter SN_ASC = new LogSorter(SN);
    public  static final LogSorter OWNER_ASC = new LogSorter(OWNER);
    public  static final LogSorter PAGENAME_ASC = new LogSorter(PAGENAME);
    public  static final LogSorter ERRMSG_ASC = new LogSorter(ERRMSG);
    public  static final LogSorter STATUS_ASC = new LogSorter(STATUS);
    public  static final LogSorter PAGEPATH_ASC = new LogSorter(PAGEPATH);
    public  static final LogSorter CRTDAY_ASC = new LogSorter(CRTDAY);
    public  static final LogSorter UPDDAY_ASC = new LogSorter(UPDDAY);
    public  static final LogSorter HOSTIP_ASC = new LogSorter(HOSTIP);
    public  static final LogSorter CRTNAME_ASC = new LogSorter(CRTNAME);
    
    public  static final LogSorter SN_DESC = new LogSorter(-SN);
    public  static final LogSorter OWNER_DESC = new LogSorter(-OWNER);
    public  static final LogSorter PAGENAME_DESC = new LogSorter(-PAGENAME);
    public  static final LogSorter ERRMSG_DESC = new LogSorter(-ERRMSG);
    public  static final LogSorter STATUS_DESC = new LogSorter(-STATUS);
    public  static final LogSorter PAGEPATH_DESC = new LogSorter(-PAGEPATH);
    public  static final LogSorter CRTDAY_DESC = new LogSorter(-CRTDAY);
    public  static final LogSorter UPDDAY_DESC = new LogSorter(-UPDDAY);
    public  static final LogSorter HOSTIP_DESC = new LogSorter(-HOSTIP);
    public  static final LogSorter CRTNAME_DESC = new LogSorter(-CRTNAME);
    
	/**
	 * 
	 */
	public LogSorter(int sortType) {
		  this.sortType = sortType;
	}
	
	@Override
	public int compare(Viewer viewer, Object e1, Object e2) {
		BaseDataEntity row1 = (BaseDataEntity)e1;
		BaseDataEntity row2 = (BaseDataEntity)e2;
		switch(sortType){
			case SN:{
				Integer i1 = row1.gpiv("sn");
				Integer i2 = row2.gpiv("sn");
				return i1.compareTo(i2);
			}
			case -SN:{
				Integer i1 = row1.gpiv("sn");
				Integer i2 = row2.gpiv("sn");
				return i2.compareTo(i1);
			}
			case OWNER:{
				String s1 = row1.gpsv("owner");
				String s2 = row2.gpsv("owner");
				return s1.compareTo(s2);
			}
			case -OWNER:{
				String s1 = row1.gpsv("owner");
				String s2 = row2.gpsv("owner");
				return s2.compareTo(s1);
			}
			case PAGENAME:{
				String s1 = row1.gpsv("pagename");
				String s2 = row2.gpsv("pagename");
				return s1.compareTo(s2);
			}
			case -PAGENAME:{
				String s1 = row1.gpsv("pagename");
				String s2 = row2.gpsv("pagename");
				return s2.compareTo(s1);
			}
			case ERRMSG:{
				String s1 = row1.gpsv("errmsg");
				String s2 = row2.gpsv("errmsg");
				return s1.compareTo(s2);
			}
			case -ERRMSG:{
				String s1 = row1.gpsv("errmsg");
				String s2 = row2.gpsv("errmsg");
				return s2.compareTo(s1);
			}
			case STATUS:{
				String s1 = row1.gpsv("status");
				String s2 = row2.gpsv("status");
				return s1.compareTo(s2);
			}
			case -STATUS:{
				String s1 = row1.gpsv("status");
				String s2 = row2.gpsv("status");
				return s2.compareTo(s1);
			}
			case PAGEPATH:{
				String s1 = row1.gpsv("pagepath");
				String s2 = row2.gpsv("pagepath");
				return s1.compareTo(s2);
			}
			case -PAGEPATH:{
				String s1 = row1.gpsv("pagepath");
				String s2 = row2.gpsv("pagepath");
				return s2.compareTo(s1);
			}
			case CRTDAY:{
				String s1 = row1.gpsv("crtday");
				String s2 = row2.gpsv("crtday");
				return s1.compareTo(s2);
			}
			case -CRTDAY:{
				String s1 = row1.gpsv("crtday");
				String s2 = row2.gpsv("crtday");
				return s2.compareTo(s1);
			}
			case UPDDAY:{
				String s1 = row1.gpsv("updday");
				String s2 = row2.gpsv("updday");
				return s1.compareTo(s2);
			}
			case -UPDDAY:{
				String s1 = row1.gpsv("updday");
				String s2 = row2.gpsv("updday");
				return s2.compareTo(s1);
			}
			case HOSTIP:{
				String s1 = row1.gpsv("hostip");
				String s2 = row2.gpsv("hostip");
				return s1.compareTo(s2);
			}
			case -HOSTIP:{
				String s1 = row1.gpsv("hostip");
				String s2 = row2.gpsv("hostip");
				return s2.compareTo(s1);
			}
			case CRTNAME:{
				String s1 = row1.gpsv("crtname");
				String s2 = row2.gpsv("crtname");
				return s1.compareTo(s2);
			}
			case -CRTNAME:{
				String s1 = row1.gpsv("crtname");
				String s2 = row2.gpsv("crtname");
				return s2.compareTo(s1);
			}
		}
		return 0;
	}

}
